home *** CD-ROM | disk | FTP | other *** search
- Path: sn.no!usenet
- From: elvemo@sn.no (Rune Elvemo)
- Newsgroups: comp.lang.c
- Subject: Problem with program
- Date: Thu, 18 Jan 1996 07:12:33 GMT
- Organization: SN Internett
- Message-ID: <4dkr5u$ro7@hasle.sn.no>
- NNTP-Posting-Host: af-04.kvadraturen.vgs.no
- X-Newsreader: Forte Free Agent 1.0.82
-
- Anyone who can figure out what is wrong with this program?
-
- I tried to compile it, but my compiler wouldn't.....
-
- Ex: It said that the prototype needed a semicolon, but it
- don't.........
-
-
-
- /* Loadfile.c - loads a txt file, and shows it
- **
- **
- */
-
- #include <stdio.h>
-
- struct Text
- {
- char *str;
- struct Text *next;
- }
-
-
- enum BOOL { TRUE, FALSE };
-
- /* prototype */
- void PText(struct Text *);
-
-
- main(int argc, char *argv[])
- {
- BOOL done = FALSE;
- FILE *txtfile;
- struct Text *first, *tst;
-
- if (argc >1)
- {
- if (txtfile = fopen(argv[1], "r"))
- {
- if(first = calloc(1, sizeof(struct Text)))
- {
- tst = first;
- if (fgetc(txtfile) != -1)
- {
- while (!done)
- {
- if (tst->str = calloc(256, sizeof(char)))
- {
- do
- {
- *tst->str = fgetc(txtfile);
- tst->str++;
- *tst->str = 0;
- /* check if the last char was LineFeed or EOF */
-
- } while ((*(tst->str - 1) != -1) &&
- (*(tst->str) != 10));
-
- if (*tst->str == -1)
- done = TRUE;
- else
- {
- if (tst->next = calloc(1,
- sizeof(struct Text)))
- {
- tst = tst->next;
-
- }
- else
- {
- done = TRUE;
- printf("\n**!!Not enough
- memory!!**\n");
- }
- }
- }
- }
- tst->next = calloc(1, sizeof(struct Text));
-
-
- PText(first);
- }
- }
- else
- printf("\n**!!Not enough memory!!**\n");
- }
- }
- }
-
- /* Print the text that we have got */
- void PText(struct Text *txt)
- {
- BOOL done = FALSE;
- struct Text *jump;
-
- jump = txt;
-
- while(!done)
- {
- printf("%s", jump->str);
-
- while (*txt->next != 0)
- {
- jump = jump->next;
-
- printf("%s\n", jump);
- }
- }
- }
- Rune Elvemo
- elvemo@oslonett.no
-
-